//
//  LGTPushUtil.swift
//  KJLGT
//
//  Created by jenkin on 2019/9/12.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTPushUtil: NSObject {
    static let share:LGTPushUtil = LGTPushUtil()
    var pushInfo:Dictionary<String, Any>?
    //推送处理
    func pushAction(appdelegate:AppDelegate, pushInfo:Dictionary<String, Any>){
        self.pushInfo = pushInfo
        let rootVC = appdelegate.window?.rootViewController
        if rootVC == nil{
            //推送数据等待处理
            self.pushInfo = pushInfo
            return
        }
        
        //跳转指定页面
        if rootVC?.classForCoder == LGTTabBarVC.classForCoder(){
            let payloadSrt:String = pushInfo["payload"] as? String ?? ""
            let payload:Dictionary<String, Any> = BaseUtil.baseUtil.getDictionaryFromJSONString(jsonString: payloadSrt)
            let url:String = payload["url"] as? String ?? ""
            if url.count == 0{
                return
            }
            let mainVC:LGTTabBarVC = rootVC as! LGTTabBarVC
            let nav:UINavigationController = mainVC.selectedViewController as! UINavigationController
            
            let vc:UIViewController? = nav.viewControllers.last
            if vc == nil{
                return
            }
            LGTViewUtil.share.gotoVC(nav: nav, currentVC: vc!, urlStr: url)
            self.pushInfo = nil
        }
    }
    
    
}
